<!--
 * @Date: 2022-06-09 09:40:07
 * @Author: 陶子
 * @LastEditTime: 2022-07-29 10:01:51
 * @FilePath: \jk_one-stop_cloud_mobile_v1.0\src\views\warehouseManagement\warehouse\warehouseList.vue
 * @pageName: 这是--(仓库管理)--页面
-->
<template>
  <div>
    <div class="room-content">
      <Navbar :appTitle="appTitle" key="1" />
      <Search style='padding-top:0.1rem' ref="topSearch" class="search" placeholder="仓库名称 | 仓库编号" :isAdd="true" :isScreen="true" @onSearch="onSearch" @onScreen="onScreen"
        @newBuild='newBuild("add",null)'></Search>
      <search-tag ref="SearchTag" @getCategory="getCategory">
      </search-tag>
      <div class="serach-content">
        <div class="content">
          <div class="tapbtn" @click="tapChange(item)" v-for="(item, index) in tabList" :key="index" :class="{ active: item.value == active }">{{ item.text }}</div>
        </div>
      </div>
      <!--分页列表 -->
      <div class="listBox">
        <pageList @handleList='handleList' ref="pageList" :checkedShow="false" :columns="columns" :listUrl="listUrl">
          <div slot='body' slot-scope="{item}">
            <div class="lineOne">仓库编号：<span>{{item.applyNumber}}</span></div>
            <div class="lineOne">仓库分类：<span>{{item.warehouseTypeTxt}}</span></div>
            <div class="lineOne">仓库管理员：<span>{{item.administerUserName}}</span></div>
          </div>
          <div slot="label" slot-scope="{item}" class="labelBox">
            <div class="itemLabel">{{item.flowStatusTxt}}</div>
            <div class="itemLabel">{{item.statusTxt}}</div>
          </div>
          <div slot="foot" slot-scope="{item}" class="operateBox">
            <div class="pubBtn" v-if="item.flowStatus == 'RUNNING'"><span @click.stop="handleWithdraw(item)" v-if="item.createBy == loginUser">撤回</span></div>
            <div class="pubBtn" v-else>
              <span style="margin-right:0.12rem" @click.stop="newBuild('edit',item)" v-if="item.flowStatus !== 'TERMINATED' && item.flowStatus !== 'REFUSE'">编辑</span>
              <span @click.stop="deleteItem(item)" v-if="item.flowStatus !== 'TERMINATED' && item.flowStatus !== 'REFUSE'">删除</span>
            </div>
          </div>
        </pageList>
      </div>
      <!-- dialog弹框 -->
      <van-dialog v-model="showDialog" show-cancel-button confirm-button-color="#1890FF" @confirm='dialogConfirm'>
        <div slot="title" class="dialogContentBox">
          <van-icon name="question-o" size="0.20rem" color="#FF943E" /><span style="margin-left: 0.07rem">{{operateInfo.title}}</span>
        </div>
        <div style="margin: 0.1rem 0.46rem 0.3rem 0.46rem; color: #888888">
          {{operateInfo.content}}
        </div>
        <div style="background: #f0f0f0; width: 100%; height: 0.01rem"></div>
      </van-dialog>
    </div>
  </div>
</template>

<script>
import Search from "@/components/search";
import SearchTag from "./SearchTag";
import Navbar from "@/components/navBar/navBar_right";
import TabBar from "@/components/TabBar";
import pageList from "@/components/pageList";
import { APILX } from "@/api/requestLx";
import { processTaskCompletionStatics } from "@/api/mobile";
import { getEnableOne } from "@/api/api";
export default {
  name: "carRoomList",
  components: { Navbar, TabBar, pageList, Search, SearchTag },
  data() {
    return {
      listUrl: "/wms/wmsWarehouse/list", //列表接口
      columns: {
        titleKey: "warehouseName", //标题
      },
      keyword: "",
      active: "",
      tabList: [],
      filterForm: {},
      appTitle: "仓库管理",
      loginUser: "",
      showDialog: false,
      itemInfo: {},
      operateInfo: {
        title: "",
        content: "",
        type: "",
      },
    };
  },
  beforeRouteLeave(to, from, next) {
    if (this.$refs.SearchTag.showSearchTag) {
      this.appTitle = "仓库管理";
      this.$refs.SearchTag.showSearchTag = false;
      this.$forceUpdate();
      next(false);
    } else {
      next();
    }
  },
  created() {
    let user = localStorage.getItem("pro__Login_Userinfo");
    this.loginUser = JSON.parse(user).value.id;
    APILX.wmsWarehouseGetTypeList().then((res) => {
      if (res.code == 200) {
        this.tabList = res.result;
        let tabObj = {
          text: "全部",
          title: "全部",
          value: "",
        };
        this.tabList.unshift(tabObj);
      }
    });
    getEnableOne({ id: "WMS_WAREHOUSE", type: "add" }).then((res) => {
      if (res.result && res.result == "false") {
        this.columns.labelKey.shift();
      }
    });
  },
  mounted() {
    this.appTitle = "仓库管理";
    let searchObj = {
      keyword: this.keyword,
    };
    this.searchQuery(searchObj);
  },
  methods: {
    // 删除操作
    deleteItem(v) {
      this.itemInfo = v;
      this.operateInfo.title = "确定删除吗？";
      this.operateInfo.content = "删除后不可恢复";
      this.operateInfo.type = "delete";
      this.showDialog = true;
    },
    /* 撤回 */
    handleWithdraw(v) {
      this.itemInfo = v;
      this.operateInfo.title = "确定撤回吗？";
      this.operateInfo.content = "撤回申请将被拒绝";
      this.operateInfo.type = "revocation";
      this.showDialog = true;
    },
    //确定撤回 || 删除
    dialogConfirm() {
      let operateType = this.operateInfo.type;
      if (operateType == "revocation") {
        APILX.operateRevoke({ flowInstId: this.itemInfo.flowInstId }).then(
          (res) => {
            if (res.code == 200) {
              this.$toast(res.message);
              let searchObj = {
                ...this.dropdownObj,
                keyword: this.keyword,
              };
              this.searchQuery(searchObj);
            } else {
              this.$toast(res.message);
            }
          }
        );
      } else {
        APILX.wmsWarehouseDelete(this.itemInfo.id).then((res) => {
          if (res.code == 200) {
            this.$toast(res.result);
            let searchObj = {
              ...this.dropdownObj,
              keyword: this.keyword,
            };
            this.searchQuery(searchObj);
          } else {
            this.$toast(res.message);
          }
        });
      }
    },
    newBuild(type, editInfo) {
      if (type == "add") {
        this.$router.push({
          path: "/addWarehouse",
          query: {
            openType: type,
          },
        });
      } else {
        this.$router.push({
          path: "/addWarehouse",
          query: {
            openType: type,
            editInfo: editInfo,
          },
        });
      }
    },
    //列表点击更多按钮事件
    handleList(id, item, type) {
      if (type == "列表") {
        this.$router.push({
          path: "/warehouseDetail",
          query: {
            id,
          },
        });
      }
    },
    tapChange(obj) {
      this.active = obj.value;
      let searchObj = {
        keyword: this.keyword,
        ...this.filterForm,
      };
      this.searchQuery(searchObj);
    },
    onSearch(v) {
      this.keyword = v;
      let searchObj = {
        ...this.filterForm,
        keyword: this.keyword,
      };
      this.searchQuery(searchObj);
    },
    onScreen() {
      this.appTitle = "更多筛选";
      this.keyword = this.$refs.topSearch.value;
      let pramsObj = JSON.parse(JSON.stringify(this.filterForm));
      pramsObj.keyword = this.keyword;
      this.$refs.SearchTag.showModal(this.keyword, pramsObj);
    },

    getCategory(sureObj) {
      this.appTitle = "仓库管理";
      this.keyword = sureObj.keyword;
      this.$refs.topSearch.value = sureObj.keyword;
      this.filterForm = JSON.parse(JSON.stringify(sureObj));
      this.searchQuery(sureObj);
    },
    // 搜索
    searchQuery(searchObj) {
      let params = {
        ...searchObj,
        warehouseType: this.active,
      };
      this.$refs.pageList.searchQuery(params);
    },
  },
};
</script>
<style lang="scss" scoped>
.room-content {
  height: 100vh;
  overflow-y: scroll;
  .serach {
    height: 0.33rem;
    background: #f2f2f6;
    border-radius: 0rem;
    margin-bottom: 0.16rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 0.33rem;
    padding: 0.1rem 0.12rem;
    // border: 1px solid red;
    .placeh {
      font-size: 0.16rem;
      font-family: PingFang SC;
      font-weight: 400;
      color: #888888;
      line-height: 0.23rem;
    }
    .icon {
      width: 0.15rem;
      height: 0.16rem;
    }
  }
  .serach-content {
    // height: 1.52rem;
    background: #ffffff;
    padding: 0 0.16rem 0.06rem 0.16rem;
    .content {
      display: flex;
      flex-wrap: wrap;
      .tapbtn {
        background: #f2f2f6;
        border-radius: 0.02rem;
        font-size: 0.16rem;
        font-family: PingFang SC;
        font-weight: 500;
        color: #888888;
        line-height: 0.23rem;
        margin-right: 0.12rem;
        margin-bottom: 0.1rem;
        text-align: center;
        padding: 0.04rem 0.12rem;
        cursor: pointer;
      }
      .active {
        color: #ffffff;
        background: #1890ff;
      }
    }
  }
}
.listBox {
  height: calc(100vh - 1.5rem);
  overflow-y: auto;
}
.operateBox {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  box-sizing: border-box;
  padding-right: 0.07rem;
  font-size: 0.14rem;
  font-weight: 500;
  color: #1890ff;
  position: relative;
  // z-index: 9999;
}
.dialogContentBox {
  text-align: left;
  margin: 0.1rem 0.19rem;
  color: #191f25;
  font-size: 0.16rem;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.pubBtn {
  margin-right: 0.12rem;
  &:nth-last-child(1) {
    margin-right: 0;
  }
}
.lineOne {
  color: #888888;
  font-size: 0.14rem;
  box-sizing: border-box;
  padding-left: 0.12rem;
  margin-top: 0.08rem;
  span {
    color: #191f25;
  }
}
.labelBox {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  position: relative;
  // top: 0.2rem;
  left: 0.15rem;
  margin-top: 0.12rem;
  .itemLabel {
    box-sizing: border-box;
    background: #f0f6fe;
    color: #1890ff;
    margin-right: 0.1rem;
    padding: 0.02rem 0.08rem;
    font-size: 0.11rem;
    border-radius: 0.03rem;
  }
}
</style>